package algocasts;

public class P80_MoveZeros {
    // Time: O(n)  Space: O(1)
    public void moveZeroes_Assign(int[] nums) {
        if (nums == null || nums.length == 0) return;
        int slow = 0;
        for (int fast = 0; fast < nums.length; fast++) {
            if (nums[fast] != 0) {
                nums[slow] = nums[fast];
                ++slow;
            }
        }
        for (int i = slow; i < nums.length; i++)
            nums[i] = 0;
    }

    // Time: O(n)  Space: O(1)
    public void moveZeroes_Swap(int[] nums) {
        if (nums == null || nums.length == 0) return;
        int slow = 0;
        for (int fast = 0; fast < nums.length; fast++)
            if (nums[fast] != 0) {
                int tmp = nums[fast];
                nums[fast] = nums[slow];
                nums[slow] = tmp;
                ++slow;
            }
    }

}
